// 导入模块 
const { log } = require('console');
const my_url = require('url');

// 解析地址 

// my_url.parse(url地址,是否深度解析)
// url地址必填 你要解析的内容
// 是否深度解析 默认是false 
//  false 不把查询字符串转对象
//  true  会把查询字符串转成对象


// http://www.baidu.com:8080/a/b/c/index.html?name=张三&age=18#abc

const res = my_url.parse('http://www.baidu.com:8080/a/b/c/index.html?name=张三&age=18#abc');
// console.log(res);

// console.log(res.query) // name=张三&age=18
// console.log(res.query.name);// undefined

/* 

Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'www.baidu.com:8080',
  port: '8080',
  hostname: 'www.baidu.com',
  hash: '#abc',
  search: '?name=张三&age=18',
  query: 'name=张三&age=18',
  pathname: '/a/b/c/index.html',
  path: '/a/b/c/index.html?name=张三&age=18',
  href: 'http://www.baidu.com:8080/a/b/c/index.html?name=张三&age=18#abc'
}





*/

const res2 = my_url.parse('http://www.baidu.com:8080/a/b/c/index.html?name=张三&age=18#abc',true);
// console.log(res2);
console.log(res2.query);
console.log(res2.query.name);
console.log(res2.query.age);



/* 
Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'www.baidu.com:8080',
  port: '8080',
  hostname: 'www.baidu.com',
  hash: '#abc',
  search: '?name=张三&age=18',
  query: [Object: null prototype] { name: '张三', age: '18' },
  pathname: '/a/b/c/index.html',
  path: '/a/b/c/index.html?name=张三&age=18',
  href: 'http://www.baidu.com:8080/a/b/c/index.html?name=张三&age=18#abc'
}


*/